﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace Invini.Tools
{
    public class BindableCommandBinding : CommandBinding
    {
        public BindableCommand ExecuteCommand
        {
            get;
            set;
        }

        public BindableCommandBinding()
        {
            this.CanExecute += this.canExecute;
            this.Executed += this.executed;
        }

        private void canExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (this.ExecuteCommand == null || this.ExecuteCommand.Command == null)
                return;

            e.CanExecute = this.ExecuteCommand.Command.CanExecute(null);
        }
        private void executed(object sender, ExecutedRoutedEventArgs e)
        {
            if (this.ExecuteCommand == null || this.ExecuteCommand.Command == null)
                return;

            this.ExecuteCommand.Command.Execute(null);
        }
    }
}
